package com.cts.tmall.app.controller;

import com.cts.tmall.biz.service.ExpressService;
import com.cts.tmall.dal.entity.TmallExpressRule;
import com.cts.tmall.dal.entity.TmallExpressTmp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/express")
public class ExpressController {

    @Autowired
    private ExpressService expressService;

    @GetMapping("/rule")
    public Map<String, Object> queryRule(@RequestParam("createUserId") Long createUserId) {
        return expressService.queryRule(createUserId);
    }

    @PutMapping("/rule")
    public void mergeRule(@RequestBody TmallExpressRule rule) {
        expressService.mergeRule(rule);
    }

    @GetMapping("/tmp")
    public List<Map<String, Object>> queryTmp(@RequestParam("createUserId") Long createUserId) {
        return expressService.queryTmp(createUserId);
    }

    @DeleteMapping("/tmp")
    public void deleteTmp(@RequestBody TmallExpressTmp tmp) {
        expressService.deleteTmp(tmp.getTmpNo());
    }

    @PostMapping("/tmp")
    public TmallExpressTmp addTmp(@RequestBody TmallExpressTmp tmp) {
        return expressService.addTmp(tmp);
    }
}
